import { localStg } from '@/utils/storage';

const _emptyInfo: Api.Auth.UserInfo = {
  buttons: [],
  roles: [],
  userId: '',
  userName: '',
};

const getToken = () => {
  return localStg.get('token') || '';
};

const getUserInfo = () => {
  const userInfo = localStg.get('userInfo') || _emptyInfo;
  if (!userInfo.buttons) {
    userInfo.buttons = [];
  }
  return userInfo;
};

const clearAuthStorage = () => {
  localStg.remove('token');
  localStg.remove('userInfo');
  localStg.remove('refreshToken');
};

export { getToken, getUserInfo, clearAuthStorage };
